package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;

public class PWDDemo1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入用户名");
        String username = scanner.nextLine();
        System.out.println("请修改密码");
        String password = scanner.nextLine();
        System.out.println("请修改昵称");
        String nickname = scanner.nextLine();
        System.out.println("请修改年龄");
        int age = Integer.parseInt(scanner.nextLine());
        try ( Connection connection=DBUtil.getConnection()){
            String sql="UPDATE user " +
                    "SET password=?,nickname=?,age=? " +
                    "WHERE username= ?";
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setString(1,password);
            ps.setString(2,nickname);
            ps.setInt(3,age);
            ps.setString(4,username);
            int num=ps.executeUpdate();
            System.out.println(num>0?"修改成功":"修改失败");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
